home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15 / Blue / FSSpecification.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  5.0 KB  |  186 lines  |  [TEXT/CWIE]

  1.  
  2. #pragma once
  3.  
  4. #ifndef __FSSPECIFICATION__
  5. #define __FSSPECIFICATION__
  6.  
  7. #include <ConditionalMacros.h>
  8. #include "MoreStrings.h"
  9.  
  10. #include <Files.h>
  11. #include <Processes.h>
  12. #include <Resources.h>
  13.  
  14. class TDescriptor;
  15.  
  16. enum
  17. {
  18.     kDontCreateFile = false,
  19.     kForceFileCreation = true,
  20.     kDefaultPerm = 0x7F
  21. };
  22.  
  23.  
  24. typedef SInt16 OpenFileRefNum;
  25. typedef SInt32 OffsetInFile;
  26. typedef SInt16 OpenResFileRefNum;
  27.  
  28. enum
  29. {
  30.     kInvalidOpenRefNum            = -1,
  31.     kInvalidOpenResRefNum        = -1
  32. };
  33.  
  34.  
  35.  
  36. class TString;
  37.  
  38. //========================================================================================
  39. // CLASS TFSSpecification
  40. //========================================================================================
  41.  
  42. class TFSSpecification
  43. {
  44.     //
  45.     // Only TOpenFileRefNum can open a file
  46.     //
  47.     friend class TOpenFileRefNum;
  48.     friend class TOpenResFileRefNum;
  49.     
  50. public:
  51.     TFSSpecification();
  52.     TFSSpecification(const FSSpec&);
  53.     TFSSpecification(const TFSSpecification&);
  54.     TFSSpecification(const TDescriptor&, Boolean forceCreate = false, OSType creator = 0, OSType fileType = 0);
  55.  
  56.     TFSSpecification(const ProcessSerialNumber& psn);
  57.     
  58.     
  59.     ~TFSSpecification();
  60.     
  61.     const TFSSpecification&    operator=(const TFSSpecification& rhs);
  62.     Boolean                    operator==(const TFSSpecification& rhs) const;
  63.  
  64.     OSStatus                Validate();
  65.  
  66.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  67.     //::  Common methods of TFSSpecification
  68.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  69.     
  70.     OSStatus                Delete();
  71.     OSStatus                Move(TFSSpecification& destinationOfMove);
  72.     OSStatus                Rename(const TString& newName);
  73.     OSStatus                ExchangeFiles(TFSSpecification& exchangeWith);
  74.  
  75.     OSStatus                GetFinderInfo(FInfo& fndrInfo) const;
  76.     OSStatus                SetFinderInfo(const FInfo& fndrInfo) const;
  77.  
  78.     OSStatus                CreateNewChildFile(const TString& newName, OSType creator, OSType fileType, TFSSpecification& newFile) const;
  79.     OSStatus                CreateNewChildFolder(const TString& newName, TFSSpecification& newFolder) const;
  80.     
  81.     OSStatus                ContainerSpecification(TFSSpecification& container) const;
  82.     OSStatus                VolumeSpecification(TFSSpecification& volume) const;
  83.     
  84.     OSStatus                Name(TString& fileName) const;
  85.     
  86.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  87.     //::  Less-common methods of TFSSpecification (Avoid using these routines)
  88.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  89.  
  90.     operator                FSSpec() const;
  91.  
  92.     operator const FSSpec*() const { return &fFileSpec; }
  93.     operator FSSpec*() { return &fFileSpec; }
  94.  
  95.     SInt16                    VRefNum() const { return fFileSpec.vRefNum; }
  96.     SInt32                    ParentDirID() const { return fFileSpec.parID; }
  97.     OSStatus                AdoptSpec(SInt16 vRefNum, SInt32 dirID);
  98.  
  99.     OSStatus                GetDirID(SInt32& dirID) const;
  100.     OSStatus                MakeFSSpec(SInt16 vRefNum, SInt32 dirID, ConstStr255Param name);
  101.  
  102.     OSStatus                CreateFile(OSType creator, OSType fileType, ScriptCode scriptTag = 0);
  103.     
  104.  
  105.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  106.     //::  Protected / private methods of TFSSpecification
  107.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  108.  
  109. protected:
  110.  
  111.     OSStatus                Open(OpenFileRefNum& refNum, SInt8 permission = kDefaultPerm) const;
  112.     OSStatus                OpenResFile(OpenResFileRefNum& refNum, SInt32 permission) const;
  113.     
  114. private:
  115.  
  116.     FSSpec                    fFileSpec;
  117.  
  118.  
  119. };
  120.  
  121. //========================================================================================
  122. // CLASS TOpenFileRefNum
  123. //========================================================================================
  124.  
  125. class TOpenFileRefNum
  126. {
  127. public:
  128.  
  129.     TOpenFileRefNum() : fRefNum(kInvalidOpenRefNum), fIsOpen(false) {}
  130.     TOpenFileRefNum(const OpenFileRefNum& refNum) : fRefNum(refNum), fIsOpen(true) {}
  131.     
  132.     OSStatus                Open(const TFSSpecification& fileToOpen, SInt8 permission = kDefaultPerm);
  133.     OSStatus                Close();
  134.     Boolean                    IsOpen() { return fIsOpen; }
  135.     
  136.     OSStatus                Read(SInt32* count, void* buffPtr);
  137.     OSStatus                Write(SInt32* count, void *buffPtr);
  138.     
  139.     OSStatus                GetEndOfFile(OffsetInFile* logEOF);
  140.     OSStatus                SetEndOfFile(OffsetInFile logEOF);
  141.     OSStatus                GetFilePosition(OffsetInFile* filePos);
  142.     OSStatus                SetFilePosition(OffsetInFile posOff);
  143.  
  144.  
  145. protected:
  146.  
  147.     OSStatus                SetFilePosition(SInt16 posMode, SInt32 posOff);
  148.  
  149. private:
  150.     OpenFileRefNum            fRefNum;
  151.     OffsetInFile            fCurrentPosition;
  152.     Boolean                    fIsOpen;
  153. };
  154.  
  155. //
  156. // Maybe later....
  157. //
  158. #if 0
  159.  
  160. struct FInfo {
  161.     OSType                            fdType;                        /*the type of the file*/
  162.     OSType                            fdCreator;                    /*file's creator*/
  163.     unsigned SInt16                    fdFlags;                    /*flags ex. hasbundle,invisible,locked, etc.*/
  164.     Point                            fdLocation;                    /*file's location in folder*/
  165.     SInt16                            fdFldr;                        /*folder containing file*/
  166. };
  167.  
  168. class TFinderInfo
  169. {
  170. public:
  171.     TFinderInfo();
  172.     TFinderInfo(const FInfo& fndrInfo);
  173.  
  174.     OSType                            FileType()            { return fFinderInfo.fdType; }
  175.     OSType                            FileCreator()        { return fFinderInfo.fdCreator; }
  176.     Point                            FileLocation()
  177.     
  178. private:
  179.     FInfo                            fFinderInfo;
  180. };
  181.  
  182. #endif // if 0
  183.  
  184.  
  185. #endif
  186.